package com.huwei.data;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;


import com.huwei.vo.TargetCacheInfo;

/**
 * 	缓存接口，用于顺序从本地缓存和redis缓存中读取和存储数据；
 * @author Administrator
 *
 */
public interface CacheDataSource {
	/**
	 * save类方法将在cache中不存在该key时将其保存，反之：cache中存在给定的key值时，将不保存；可对应spring中的@Cacheable注解的模式；
	 * @param key
	 * @param value
	 * @return
	 */
	Object save(TargetCacheInfo targetCacheInfo ,Object value);
	/**
	 * timeout时间单位，默认为毫秒
	 * @param key
	 * @param value
	 * @param timeout
	 * @return
	 */
	Object save(TargetCacheInfo targetCacheInfo ,Object value ,long timeout);
	
	Object save(TargetCacheInfo targetCacheInfo ,Object value ,long timeout ,TimeUnit timeUnit);
	
	<V> V save(TargetCacheInfo targetCacheInfo ,Callable<V> callable);
	
	<V> V save(TargetCacheInfo targetCacheInfo ,Callable<V> callable ,long timeout);
	
	<V> V save(TargetCacheInfo targetCacheInfo ,Callable<V> callable ,long timeout ,TimeUnit timeUnit); 
	/**
	 * update类别的方法，将始终保存给定的值到cache中；可对应spring的@Put注解的模式
	 * @param key
	 * @param value
	 * @return
	 */
	Object update(TargetCacheInfo targetCacheInfo ,Object value);
	
	Object update(TargetCacheInfo targetCacheInfo ,Object value ,long timeout);
	
	Object update(TargetCacheInfo targetCacheInfo ,Object value ,long timeout ,TimeUnit timeUnit);
	
	<V> V update(TargetCacheInfo targetCacheInfo ,Callable<V> callable);
	
	<V> V update(TargetCacheInfo targetCacheInfo ,Callable<V> callable ,long timeout);
	
	<V> V update(TargetCacheInfo targetCacheInfo ,Callable<V> callable ,long timeout ,TimeUnit timeUnit); 
	
	Object find(TargetCacheInfo targetCacheInfo );
	
	void delete(TargetCacheInfo targetCacheInfo );
}
